Skip to content

fix: show maintenance message when LNbits is down - #76

Merged
helloscoopa merged 2 commits into
mainfrom
xbuddhi/fix/lnbits-maintenance-mode
Nov 8, 2026
Merged

helloscoopa merged 2 commits into
mainfrom
xbuddhi/fix/lnbits-maintenance-mode

Conversation

@xbuddhi

@xbuddhi xbuddhi commented Nov 8, 2026 •

Copy link
Copy Markdown

Problem

When LNbits stops responding:

  • /balance shows 0 sats, so users think their funds are gone.

  • Other commands hang for up to 2 minutes (the default req timeout), then fail with mixed errors, or with no reply at all (inline send).

Fix

  • Health tracking (internal/lnbits/health.go): every LNbits request goes through a transport that records the outcome. Connection errors, timeouts and 502/503/504 mark LNbits as down. Any other answer (including 4xx/500) marks it up. A background probe calls /api/v1/health every 15s, so the bot recovers on its own.

  • Telegram gate (internal/telegram/maintenance.go): handlers that need LNbits now stop early while it is down and reply at once:

    🛠 BitcoinDeepa is under maintenance. Your funds are safe. Please try again in a few minutes.

    Buttons get an alert, and inline queries get an error result. In groups, only commands get a reply, so normal chat doesn't trigger spam. Help, convert/price and cancel buttons still work.

  • /balance never shows a made-up 0. While down, it shows the maintenance message plus the last known balance from the DB. Other errors show "try again later".

  • Timeouts: LNbits calls now time out after 15s instead of 2 min. Payments keep their 24h timeout.

  • Admin alert (internal/telegram/lnbits_alert.go): if LNbits stays down for 30s, the log group gets "🔴 LNbits is down" with the error. When it comes back, the log group gets "🟢 LNbits is back up" with the downtime. Short glitches send nothing. It uses the existing log_group_id / error thread, so there are no new config settings.

Not in this PR (follow-ups)

  • Manual maintenance switch for planned downtime

  • "Payment status unknown" wording for payments interrupted by an outage

  • API returns 503 instead of balance: 0

Testing

  • New tests in internal/lnbits/health_test.go cover status handling, connection errors, probe recovery, a zero-value client and change events. lnbits_alert_test.go covers the 30s alert delay. All pass.

  • go build ./... passes.

  • internal/telegram has 5 failing tests (referral, tooltip). They fail the same way on main.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

When LNbits stopped responding, /balance showed a 0 balance and other
commands hung for up to 2 minutes before failing with mixed errors.

- Track LNbits health on every request: connection errors, timeouts and
  502/503/504 mark it down; any other answer marks it up. A background
  probe checks /api/v1/health every 15s so the bot recovers on its own.
- Gate LNbits-dependent Telegram handlers: while down they reply at once
  with a maintenance message (callback alert / inline result as fitting;
  silent for non-command group messages). Help, convert and cancel
  buttons keep working.
- /balance never shows a made-up 0: it shows the maintenance message
  plus the last known balance, or "try again later" for other errors.
- Cut the LNbits request timeout from 2 minutes to 15s. Payments keep
  their 24h timeout.
@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 54c86781-2ad3-4f7b-a298-61bb4d8c3c1f
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Sends a message to the log group when LNbits has been unreachable for
30s, and a recovery message with the downtime once it answers again.
The delay keeps a single failed request from paging anyone; short
outages send no alerts at all.

@helloscoopa helloscoopa left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@helloscoopa
helloscoopa merged commit 3b3bf02 into main Nov 8, 2026
1 of 3 checks passed
@helloscoopa
helloscoopa deleted the xbuddhi/fix/lnbits-maintenance-mode branch November 8, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants